

clear all

*cd 

*This file created the present values under uncertainty depending on (i) the estimate of water reduction, (ii) risk preferences parameters (risk neutral, risk averse, probability weights) and discounting rates. If you see note "Manual change for (i)" or "Manuel change for (ii)", you should activate one of the available options depending on the estimate of water reduction (i) or risk preference parameter (ii) needed in each case of Table 3. You will find 7 manual changes in lines 65, 692,731,804,821,886, 906.

use predictedm3_osf.dta, clear



*ITT
*****

*Using quantiles 5 and 95 from QR regression for panel analysis
local ltitt_1=2.75 
local ltitt_4=1.81 
    
*% of control M3
local ltittp_1=0.1124 
local ltittp_4=0.0741 




*ITTFM (ITT first month)
******
*Using quantile regression to calculate the extreme values
local ltittfm_1=6.04
local ltittfm_4=0.04 
  
*% of control M3
local ltittfmp_1=0.2472
local ltittfmp_4=0.0017



*ITTnb (ITT no bonus)
******
*Using quantile regression to calculate the extreme values
local ltittnb_1=2.61
local ltittnb_4=1.98 
  
*% of control M3
local ltittnbp_1=0.1068
local ltittnbp_4=0.0812
  
  
  
*ITTFM_nb (ITT no bonus)
******
*Using quantile regression to calculate the extreme values
local ltittfmnb_1=8.93
local ltittfmnb_4=0.03 
  
*% of control M3
local ltittfmnbp_1=0.3657
local ltittfmnbp_4=0.0014

*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*Manual change for (i): Activate the estimate of water reduction
foreach t in 1 4{
foreach y in 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025{
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
*gen r`y'`x'_`t'=m3`y'`x'- `ltitt_`t''
gen r`y'`x'_`t'=m3`y'`x'*(1- `ltittp_`t'')

*gen r`y'`x'_`t'=m3`y'`x'*(1- `ltittfmp_`t'')
*gen r`y'`x'_`t'=m3`y'`x'*(1- `ltittnbp_`t'')
*gen r`y'`x'_`t'=m3`y'`x'*(1- `ltittfmnbp_`t'')
replace r`y'`x'_`t'=0 if r`y'`x'_`t'<0
}
}
}
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



************************************************************************************************************
*** Adding tariffs to create predicted payments
************************************************************************************************************

* 2015-2017 Tariffs
********************
local p1=1.5431
local p4=1.0

*set trace on

foreach q in 1 4{


**** Asada Moracia

foreach y in 2015 2016 2017 {
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
gen p`y'`x'_`q'=(2695+155*m3`y'`x') if m3`y'`x'<=10 & codcom==64
replace p`y'`x'_`q'=(2695+155*10+170*(m3`y'`x' -10)) if m3`y'`x'>10 & m3`y'`x'<=30 & codcom==64
replace p`y'`x'_`q'=(2695+155*10+170*20+185*(m3`y'`x' -30)) if m3`y'`x'>30 & m3`y'`x'<=60 & codcom==64
replace p`y'`x'_`q'=(2695+155*10+170*20+185*30 +200*(m3`y'`x' -60)) if m3`y'`x'>60 & codcom==64

foreach t in 1 4{
	gen p1`y'`x'_`t'_`q'=(2695+155*r`y'`x'_`t') if r`y'`x'_`t'<=10 & codcom==64
	replace p1`y'`x'_`t'_`q'=(2695+155*10+170*(r`y'`x'_`t' -10)) if r`y'`x'_`t'>10 & r`y'`x'_`t'<=30 & codcom==64
	replace p1`y'`x'_`t'_`q'=(2695+155*10+170*20+185*(r`y'`x'_`t' -30)) if r`y'`x'_`t'>30 & r`y'`x'_`t'<=60 & codcom==64
	replace p1`y'`x'_`t'_`q'=(2695+155*10+170*20+185*30 +200*(r`y'`x'_`t' -60)) if r`y'`x'_`t'>60 & codcom==64
	gen s`y'`x'_`t'_`q'=p`y'`x'_`q'-p1`y'`x'_`t'_`q' if  codcom==64
	replace s`y'`x'_`t'_`q'=. if m3`y'`x'==. & codcom==64
	}
}
}


/*
Paso Tempisque, Chomes, San Blas, Lepanto 
*/

foreach y in 2015 2016 2017{
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
replace p`y'`x'_`q'=(3415+160*m3`y'`x') if m3`y'`x' <=10 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
replace p`y'`x'_`q'=(3415+160*10+170*(m3`y'`x' -10)) if m3`y'`x'>10 & m3`y'`x'<=30 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
replace p`y'`x'_`q'=(3415+160*10+170*20+180*(m3`y'`x' -30)) if m3`y'`x'>30 & m3`y'`x'<=60 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
replace p`y'`x'_`q'=(3415+160*10+170*20+180*30 + 195*(m3`y'`x' -60)) if m3`y'`x'>60 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 

foreach t in 1 4{
	replace p1`y'`x'_`t'_`q'=(3415+160*r`y'`x'_`t') if r`y'`x'_`t'<=10 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
	replace p1`y'`x'_`t'_`q'=(3415+160*10+170*(r`y'`x'_`t' -10)) if r`y'`x'_`t'>10 & r`y'`x'_`t'<=30 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
	replace p1`y'`x'_`t'_`q'=(3415+160*10+170*20+180*(r`y'`x'_`t' -30)) if r`y'`x'_`t'>30 & r`y'`x'_`t'<=60 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
	replace p1`y'`x'_`t'_`q'=(3415+160*10+170*20+180*30 +195*(r`y'`x'_`t' -60)) if r`y'`x'_`t'>60 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
	replace s`y'`x'_`t'_`q'=p`y'`x'_`q'-p1`y'`x'_`t'_`q' if  (codcom==48 | codcom==36 | codcom==31 | codcom==66)
	replace s`y'`x'_`t'_`q'=. if m3`y'`x'==. & (codcom==48 | codcom==36 | codcom==31 | codcom==66)
	}

}
}

**** Asada Jocotes

foreach y in 2015 2016 2017 {
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
replace p`y'`x'_`q'=2745+150*m3`y'`x' if codcom==35

foreach t in 1 4{

	replace p1`y'`x'_`t'_`q'=2745+150*r`y'`x'_`t' if codcom==35
	replace s`y'`x'_`t'_`q'=p`y'`x'_`q'-p1`y'`x'_`t'_`q' if  codcom==35
	replace s`y'`x'_`t'_`q'=. if m3`y'`x'==. & codcom==35
	}
}
}

**** Asada Lomas de Matapalo


foreach y in 2015 2016 2017{
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
replace p`y'`x'_`q'=(3180+185*m3`y'`x') if m3`y'`x' <=10 & codcom==25
replace p`y'`x'_`q'=(3180+185*10+195*(m3`y'`x' -10)) if m3`y'`x'>10 & m3`y'`x'<=30 & codcom==25
replace p`y'`x'_`q'=(3180+185*10+195*20+210*(m3`y'`x' -30)) if m3`y'`x'>30 & m3`y'`x'<=60 & codcom==25 
replace p`y'`x'_`q'=(3180+185*10+195*20+210*30 +225*(m3`y'`x' -60)) if m3`y'`x'>60 & codcom==25 


foreach t in 1 4{

	replace p1`y'`x'_`t'_`q'=(3180+185*r`y'`x'_`t') if r`y'`x'_`t'<=10 & codcom==25
	replace p1`y'`x'_`t'_`q'=(3180+185*10+195*(r`y'`x'_`t' -10)) if r`y'`x'_`t'>10 & r`y'`x'_`t'<=30 & codcom==25
	replace p1`y'`x'_`t'_`q'=(3180+185*10+195*20+210*(r`y'`x'_`t' -30)) if r`y'`x'_`t'>30 & r`y'`x'_`t'<=60 & codcom==25 
	replace p1`y'`x'_`t'_`q'=(3180+185*10+195*20+210*30 +225*(r`y'`x'_`t' -60)) if r`y'`x'_`t'>60 & codcom==25
	replace s`y'`x'_`t'_`q'=p`y'`x'_`q'-p1`y'`x'_`t'_`q' if codcom==25
	replace s`y'`x'_`t'_`q'=. if m3`y'`x'==. & codcom==25
	}
}

}

**** Asada Pueblo Nuevo

foreach y in 2015 2016 2017{
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
replace p`y'`x'_`q'=(2800+190*m3`y'`x') if m3`y'`x' <=10 & codcom==47
replace p`y'`x'_`q'=(2800+190*10+200*(m3`y'`x' -10)) if m3`y'`x'>10 & m3`y'`x'<=30 & codcom==47
replace p`y'`x'_`q'=(2800+190*10+200*20+215*(m3`y'`x' -30)) if m3`y'`x'>30 & m3`y'`x'<=60 & codcom==47 
replace p`y'`x'_`q'=(2800+190*10+200*20+215*30 +230*(m3`y'`x' -60)) if m3`y'`x'>60 & codcom==47 

foreach t in 1 4{

	replace p1`y'`x'_`t'_`q'=(2800+190*r`y'`x'_`t') if r`y'`x'_`t'<=10 & codcom==47
	replace p1`y'`x'_`t'_`q'=(2800+190*10+200*(r`y'`x'_`t' -10)) if r`y'`x'_`t'>10 & r`y'`x'_`t'<=30 & codcom==47
	replace p1`y'`x'_`t'_`q'=(2800+190*10+200*20+215*(r`y'`x'_`t' -30)) if r`y'`x'_`t'>30 & r`y'`x'_`t'<=60 & codcom==47 
	replace p1`y'`x'_`t'_`q'=(2800+190*10+200*20+215*30 +230*(r`y'`x'_`t' -60)) if r`y'`x'_`t'>60 & codcom==47
	replace s`y'`x'_`t'_`q'=p`y'`x'_`q'-p1`y'`x'_`t'_`q' if  codcom==47
	replace s`y'`x'_`t'_`q'=. if m3`y'`x'==. & codcom==47
	}
}
}

**** Asada Santa Rita

foreach y in 2015 2016 2017{
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
replace p`y'`x'_`q'=(3085+190*m3`y'`x') if m3`y'`x' <=10 & codcom==32
replace p`y'`x'_`q'=(3085+190*10+200*(m3`y'`x' -10)) if m3`y'`x'>10 & m3`y'`x'<=30 & codcom==32
replace p`y'`x'_`q'=(3085+190*10+200*20+215*(m3`y'`x' -30)) if m3`y'`x'>30 & m3`y'`x'<=60 & codcom==32
replace p`y'`x'_`q'=(3085+190*10+200*20+215*30 +230*(m3`y'`x' -60)) if m3`y'`x'>60 & codcom==32

foreach t in 1 4{
	replace p1`y'`x'_`t'_`q'=(3085+190*r`y'`x'_`t') if r`y'`x'_`t'<=10 & codcom==32
	replace p1`y'`x'_`t'_`q'=(3085+190*10+200*(r`y'`x'_`t' -10)) if r`y'`x'_`t'>10 & r`y'`x'_`t'<=30 & codcom==32
	replace p1`y'`x'_`t'_`q'=(3085+190*10+200*20+215*(r`y'`x'_`t' -30)) if r`y'`x'_`t'>30 & r`y'`x'_`t'<=60 & codcom==32
	replace p1`y'`x'_`t'_`q'=(3085+190*10+200*20+215*30 +230*(r`y'`x'_`t' -60)) if r`y'`x'_`t'>60 & codcom==32
	replace s`y'`x'_`t'_`q'=p`y'`x'_`q'-p1`y'`x'_`t'_`q' if  codcom==32
	replace s`y'`x'_`t'_`q'=. if m3`y'`x'==. & codcom==32
	}	
}
}




*2018 2019 2020 
***********************


**** Asada Moracia

foreach y in 2018 2019 2020 {
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
gen p`y'`x'_`q'=(2695+155*m3`y'`x')*`p`q'' if m3`y'`x'<=10 & codcom==64
replace p`y'`x'_`q'=(2695+155*10+170*(m3`y'`x' -10))*`p`q'' if m3`y'`x'>10 & m3`y'`x'<=30 & codcom==64
replace p`y'`x'_`q'=(2695+155*10+170*20+185*(m3`y'`x' -30))*`p`q'' if m3`y'`x'>30 & m3`y'`x'<=60 & codcom==64
replace p`y'`x'_`q'=(2695+155*10+170*20+185*30 +200*(m3`y'`x' -60))*`p`q'' if m3`y'`x'>60 & codcom==64

foreach t in 1 4{
	gen p1`y'`x'_`t'_`q'=(2695+155*r`y'`x'_`t')*`p`q'' if r`y'`x'_`t'<=10 & codcom==64
	replace p1`y'`x'_`t'_`q'=(2695+155*10+170*(r`y'`x'_`t' -10))*`p`q'' if r`y'`x'_`t'>10 & r`y'`x'_`t'<=30 & codcom==64
	replace p1`y'`x'_`t'_`q'=(2695+155*10+170*20+185*(r`y'`x'_`t' -30))*`p`q'' if r`y'`x'_`t'>30 & r`y'`x'_`t'<=60 & codcom==64
	replace p1`y'`x'_`t'_`q'=(2695+155*10+170*20+185*30 +200*(r`y'`x'_`t' -60))*`p`q'' if r`y'`x'_`t'>60 & codcom==64
	gen s`y'`x'_`t'_`q'=p`y'`x'_`q'-p1`y'`x'_`t'_`q' if  codcom==64
	replace s`y'`x'_`t'_`q'=. if m3`y'`x'==. & codcom==64
	}
}
}


/*
Paso Tempisque, Chomes, San Blas, Lepanto 

*/

foreach y in 2018 2019 2020{
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
replace p`y'`x'_`q'=(3415+160*m3`y'`x')*`p`q'' if m3`y'`x' <=10 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
replace p`y'`x'_`q'=(3415+160*10+170*(m3`y'`x' -10))*`p`q'' if m3`y'`x'>10 & m3`y'`x'<=30 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
replace p`y'`x'_`q'=(3415+160*10+170*20+180*(m3`y'`x' -30))*`p`q'' if m3`y'`x'>30 & m3`y'`x'<=60 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
replace p`y'`x'_`q'=(3415+160*10+170*20+180*30 + 195*(m3`y'`x' -60))*`p`q'' if m3`y'`x'>60 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 

foreach t in 1 4{
	replace p1`y'`x'_`t'_`q'=(3415+160*r`y'`x'_`t')*`p`q'' if r`y'`x'_`t'<=10 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
	replace p1`y'`x'_`t'_`q'=(3415+160*10+170*(r`y'`x'_`t' -10))*`p`q'' if r`y'`x'_`t'>10 & r`y'`x'_`t'<=30 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
	replace p1`y'`x'_`t'_`q'=(3415+160*10+170*20+180*(r`y'`x'_`t' -30))*`p`q'' if r`y'`x'_`t'>30 & r`y'`x'_`t'<=60 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
	replace p1`y'`x'_`t'_`q'=(3415+160*10+170*20+180*30 +195*(r`y'`x'_`t' -60))*`p`q'' if r`y'`x'_`t'>60 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
	replace s`y'`x'_`t'_`q'=p`y'`x'_`q'-p1`y'`x'_`t'_`q' if  (codcom==48 | codcom==36 | codcom==31 | codcom==66)
	replace s`y'`x'_`t'_`q'=. if m3`y'`x'==. & (codcom==48 | codcom==36 | codcom==31 | codcom==66)
	}

}
}

**** Asada Jocotes

foreach y in 2018 2019 2020{
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
replace p`y'`x'_`q'=(2745+150*m3`y'`x')*`p`q'' if codcom==35

foreach t in 1 4{

	replace p1`y'`x'_`t'_`q'=(2745+150*r`y'`x'_`t')*`p`q'' if codcom==35
	replace s`y'`x'_`t'_`q'=p`y'`x'_`q'-p1`y'`x'_`t'_`q' if  codcom==35
	replace s`y'`x'_`t'_`q'=. if m3`y'`x'==. & codcom==35
	}
}
}

**** Asada Lomas de Matapalo


foreach y in 2018 2019 2020{
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
replace p`y'`x'_`q'=(3180+185*m3`y'`x')*`p`q'' if m3`y'`x' <=10 & codcom==25
replace p`y'`x'_`q'=(3180+185*10+195*(m3`y'`x' -10))*`p`q'' if m3`y'`x'>10 & m3`y'`x'<=30 & codcom==25
replace p`y'`x'_`q'=(3180+185*10+195*20+210*(m3`y'`x' -30))*`p`q'' if m3`y'`x'>30 & m3`y'`x'<=60 & codcom==25 
replace p`y'`x'_`q'=(3180+185*10+195*20+210*30 +225*(m3`y'`x' -60))*`p`q'' if m3`y'`x'>60 & codcom==25 


foreach t in 1 4{

	replace p1`y'`x'_`t'_`q'=(3180+185*r`y'`x'_`t')*`p`q'' if r`y'`x'_`t'<=10 & codcom==25
	replace p1`y'`x'_`t'_`q'=(3180+185*10+195*(r`y'`x'_`t' -10))*`p`q'' if r`y'`x'_`t'>10 & r`y'`x'_`t'<=30 & codcom==25
	replace p1`y'`x'_`t'_`q'=(3180+185*10+195*20+210*(r`y'`x'_`t' -30))*`p`q'' if r`y'`x'_`t'>30 & r`y'`x'_`t'<=60 & codcom==25 
	replace p1`y'`x'_`t'_`q'=(3180+185*10+195*20+210*30 +225*(r`y'`x'_`t' -60))*`p`q'' if r`y'`x'_`t'>60 & codcom==25
	replace s`y'`x'_`t'_`q'=p`y'`x'_`q'-p1`y'`x'_`t'_`q' if codcom==25
	replace s`y'`x'_`t'_`q'=. if m3`y'`x'==. & codcom==25
	}
}

}

**** Asada Pueblo Nuevo

foreach y in 2018 2019 2020{
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
replace p`y'`x'_`q'=(2800+190*m3`y'`x')*`p`q'' if m3`y'`x' <=10 & codcom==47
replace p`y'`x'_`q'=(2800+190*10+200*(m3`y'`x' -10))*`p`q'' if m3`y'`x'>10 & m3`y'`x'<=30 & codcom==47
replace p`y'`x'_`q'=(2800+190*10+200*20+215*(m3`y'`x' -30))*`p`q'' if m3`y'`x'>30 & m3`y'`x'<=60 & codcom==47 
replace p`y'`x'_`q'=(2800+190*10+200*20+215*30 +230*(m3`y'`x' -60))*`p`q'' if m3`y'`x'>60 & codcom==47 

foreach t in 1 4{

	replace p1`y'`x'_`t'_`q'=(2800+190*r`y'`x'_`t')*`p`q'' if r`y'`x'_`t'<=10 & codcom==47
	replace p1`y'`x'_`t'_`q'=(2800+190*10+200*(r`y'`x'_`t' -10))*`p`q'' if r`y'`x'_`t'>10 & r`y'`x'_`t'<=30 & codcom==47
	replace p1`y'`x'_`t'_`q'=(2800+190*10+200*20+215*(r`y'`x'_`t' -30))*`p`q'' if r`y'`x'_`t'>30 & r`y'`x'_`t'<=60 & codcom==47 
	replace p1`y'`x'_`t'_`q'=(2800+190*10+200*20+215*30 +230*(r`y'`x'_`t' -60))*`p`q'' if r`y'`x'_`t'>60 & codcom==47
	replace s`y'`x'_`t'_`q'=p`y'`x'_`q'-p1`y'`x'_`t'_`q' if  codcom==47
	replace s`y'`x'_`t'_`q'=. if m3`y'`x'==. & codcom==47
	}
}
}

**** Asada Santa Rita


foreach y in 2018 2019 2020{
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
replace p`y'`x'_`q'=(3085+190*m3`y'`x')*`p`q'' if m3`y'`x' <=10 & codcom==32
replace p`y'`x'_`q'=(3085+190*10+200*(m3`y'`x' -10))*`p`q'' if m3`y'`x'>10 & m3`y'`x'<=30 & codcom==32
replace p`y'`x'_`q'=(3085+190*10+200*20+215*(m3`y'`x' -30))*`p`q'' if m3`y'`x'>30 & m3`y'`x'<=60 & codcom==32 
replace p`y'`x'_`q'=(3085+190*10+200*20+215*30 +230*(m3`y'`x' -60))*`p`q'' if m3`y'`x'>60 & codcom==32

foreach t in 1 4{
	replace p1`y'`x'_`t'_`q'=(3085+190*r`y'`x'_`t')*`p`q'' if r`y'`x'_`t'<=10 & codcom==32
	replace p1`y'`x'_`t'_`q'=(3085+190*10+200*(r`y'`x'_`t' -10))*`p`q'' if r`y'`x'_`t'>10 & r`y'`x'_`t'<=30 & codcom==32
	replace p1`y'`x'_`t'_`q'=(3085+190*10+200*20+215*(r`y'`x'_`t' -30))*`p`q'' if r`y'`x'_`t'>30 & r`y'`x'_`t'<=60 & codcom==32
	replace p1`y'`x'_`t'_`q'=(3085+190*10+200*20+215*30 +230*(r`y'`x'_`t' -60))*`p`q'' if r`y'`x'_`t'>60 & codcom==32
	replace s`y'`x'_`t'_`q'=p`y'`x'_`q'-p1`y'`x'_`t'_`q' if  codcom==32
	replace s`y'`x'_`t'_`q'=. if m3`y'`x'==. & codcom==32
	}	
}
}




*2021-2023
***********************
local e=2

**** Asada Moracia

foreach y in 2021 2022 2023 {
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
gen p`y'`x'_`q'=(2695+155*m3`y'`x')*`p`q''^`e' if m3`y'`x'<=10 & codcom==64
replace p`y'`x'_`q'=(2695+155*10+170*(m3`y'`x' -10))*`p`q''^`e' if m3`y'`x'>10 & m3`y'`x'<=30 & codcom==64
replace p`y'`x'_`q'=(2695+155*10+170*20+185*(m3`y'`x' -30))*`p`q''^`e' if m3`y'`x'>30 & m3`y'`x'<=60 & codcom==64
replace p`y'`x'_`q'=(2695+155*10+170*20+185*30 +200*(m3`y'`x' -60))*`p`q''^`e' if m3`y'`x'>60 & codcom==64

foreach t in 1 4{
	gen p1`y'`x'_`t'_`q'=(2695+155*r`y'`x'_`t')*`p`q''^`e' if r`y'`x'_`t'<=10 & codcom==64
	replace p1`y'`x'_`t'_`q'=(2695+155*10+170*(r`y'`x'_`t' -10))*`p`q''^`e' if r`y'`x'_`t'>10 & r`y'`x'_`t'<=30 & codcom==64
	replace p1`y'`x'_`t'_`q'=(2695+155*10+170*20+185*(r`y'`x'_`t' -30))*`p`q''^`e' if r`y'`x'_`t'>30 & r`y'`x'_`t'<=60 & codcom==64
	replace p1`y'`x'_`t'_`q'=(2695+155*10+170*20+185*30 +200*(r`y'`x'_`t' -60))*`p`q''^`e' if r`y'`x'_`t'>60 & codcom==64
	gen s`y'`x'_`t'_`q'=p`y'`x'_`q'-p1`y'`x'_`t'_`q' if  codcom==64
	replace s`y'`x'_`t'_`q'=. if m3`y'`x'==. & codcom==64
	}
}
}


/*
Paso Tempisque, Chomes, San Blas, Lepanto 

*/

foreach y in 2021 2022 2023 {
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
replace p`y'`x'_`q'=(3415+160*m3`y'`x')*`p`q''^`e' if m3`y'`x' <=10 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
replace p`y'`x'_`q'=(3415+160*10+170*(m3`y'`x' -10))*`p`q''^`e' if m3`y'`x'>10 & m3`y'`x'<=30 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
replace p`y'`x'_`q'=(3415+160*10+170*20+180*(m3`y'`x' -30))*`p`q''^`e' if m3`y'`x'>30 & m3`y'`x'<=60 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
replace p`y'`x'_`q'=(3415+160*10+170*20+180*30 + 195*(m3`y'`x' -60))*`p`q''^`e' if m3`y'`x'>60 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 

foreach t in 1 4{
	replace p1`y'`x'_`t'_`q'=(3415+160*r`y'`x'_`t')*`p`q''^`e' if r`y'`x'_`t'<=10 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
	replace p1`y'`x'_`t'_`q'=(3415+160*10+170*(r`y'`x'_`t' -10))*`p`q''^`e' if r`y'`x'_`t'>10 & r`y'`x'_`t'<=30 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
	replace p1`y'`x'_`t'_`q'=(3415+160*10+170*20+180*(r`y'`x'_`t' -30))*`p`q''^`e' if r`y'`x'_`t'>30 & r`y'`x'_`t'<=60 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
	replace p1`y'`x'_`t'_`q'=(3415+160*10+170*20+180*30 +195*(r`y'`x'_`t' -60))*`p`q''^`e' if r`y'`x'_`t'>60 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
	replace s`y'`x'_`t'_`q'=p`y'`x'_`q'-p1`y'`x'_`t'_`q' if  (codcom==48 | codcom==36 | codcom==31 | codcom==66)
	replace s`y'`x'_`t'_`q'=. if m3`y'`x'==. & (codcom==48 | codcom==36 | codcom==31 | codcom==66)
	}

}
}

**** Asada Jocotes

foreach y in 2021 2022 2023 {
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
replace p`y'`x'_`q'=(2745+150*m3`y'`x')*`p`q''^`e' if codcom==35

foreach t in 1 4{

	replace p1`y'`x'_`t'_`q'=(2745+150*r`y'`x'_`t')*`p`q''^`e' if codcom==35
	replace s`y'`x'_`t'_`q'=p`y'`x'_`q'-p1`y'`x'_`t'_`q' if  codcom==35
	replace s`y'`x'_`t'_`q'=. if m3`y'`x'==. & codcom==35
	}
}
}

**** Asada Lomas de Matapalo


foreach y in 2021 2022 2023 {
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
replace p`y'`x'_`q'=(3180+185*m3`y'`x')*`p`q''^`e' if m3`y'`x' <=10 & codcom==25
replace p`y'`x'_`q'=(3180+185*10+195*(m3`y'`x' -10))*`p`q''^`e' if m3`y'`x'>10 & m3`y'`x'<=30 & codcom==25
replace p`y'`x'_`q'=(3180+185*10+195*20+210*(m3`y'`x' -30))*`p`q''^`e' if m3`y'`x'>30 & m3`y'`x'<=60 & codcom==25 
replace p`y'`x'_`q'=(3180+185*10+195*20+210*30 +225*(m3`y'`x' -60))*`p`q''^`e' if m3`y'`x'>60 & codcom==25 


foreach t in 1 4{

	replace p1`y'`x'_`t'_`q'=(3180+185*r`y'`x'_`t')*`p`q''^`e' if r`y'`x'_`t'<=10 & codcom==25
	replace p1`y'`x'_`t'_`q'=(3180+185*10+195*(r`y'`x'_`t' -10))*`p`q''^`e' if r`y'`x'_`t'>10 & r`y'`x'_`t'<=30 & codcom==25
	replace p1`y'`x'_`t'_`q'=(3180+185*10+195*20+210*(r`y'`x'_`t' -30))*`p`q''^`e' if r`y'`x'_`t'>30 & r`y'`x'_`t'<=60 & codcom==25 
	replace p1`y'`x'_`t'_`q'=(3180+185*10+195*20+210*30 +225*(r`y'`x'_`t' -60))*`p`q''^`e' if r`y'`x'_`t'>60 & codcom==25
	replace s`y'`x'_`t'_`q'=p`y'`x'_`q'-p1`y'`x'_`t'_`q' if codcom==25
	replace s`y'`x'_`t'_`q'=. if m3`y'`x'==. & codcom==25
	}
}

}

**** Asada Pueblo Nuevo

foreach y in 2021 2022 2023 {
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
replace p`y'`x'_`q'=(2800+190*m3`y'`x')*`p`q''^`e' if m3`y'`x' <=10 & codcom==47
replace p`y'`x'_`q'=(2800+190*10+200*(m3`y'`x' -10))*`p`q''^`e' if m3`y'`x'>10 & m3`y'`x'<=30 & codcom==47
replace p`y'`x'_`q'=(2800+190*10+200*20+215*(m3`y'`x' -30))*`p`q''^`e' if m3`y'`x'>30 & m3`y'`x'<=60 & codcom==47 
replace p`y'`x'_`q'=(2800+190*10+200*20+215*30 +230*(m3`y'`x' -60))*`p`q''^`e' if m3`y'`x'>60 & codcom==47 

foreach t in 1 4{

	replace p1`y'`x'_`t'_`q'=(2800+190*r`y'`x'_`t')*`p`q''^`e' if r`y'`x'_`t'<=10 & codcom==47
	replace p1`y'`x'_`t'_`q'=(2800+190*10+200*(r`y'`x'_`t' -10))*`p`q''^`e' if r`y'`x'_`t'>10 & r`y'`x'_`t'<=30 & codcom==47
	replace p1`y'`x'_`t'_`q'=(2800+190*10+200*20+215*(r`y'`x'_`t' -30))*`p`q''^`e' if r`y'`x'_`t'>30 & r`y'`x'_`t'<=60 & codcom==47 
	replace p1`y'`x'_`t'_`q'=(2800+190*10+200*20+215*30 +230*(r`y'`x'_`t' -60))*`p`q''^`e' if r`y'`x'_`t'>60 & codcom==47
	replace s`y'`x'_`t'_`q'=p`y'`x'_`q'-p1`y'`x'_`t'_`q' if  codcom==47
	replace s`y'`x'_`t'_`q'=. if m3`y'`x'==. & codcom==47
	}
}
}

**** Asada Santa Rita


foreach y in 2021 2022 2023 {
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
replace p`y'`x'_`q'=(3085+190*m3`y'`x')*`p`q''^`e' if m3`y'`x' <=10 & codcom==32
replace p`y'`x'_`q'=(3085+190*10+200*(m3`y'`x' -10))*`p`q''^`e' if m3`y'`x'>10 & m3`y'`x'<=30 & codcom==32
replace p`y'`x'_`q'=(3085+190*10+200*20+215*(m3`y'`x' -30))*`p`q''^`e' if m3`y'`x'>30 & m3`y'`x'<=60 & codcom==32
replace p`y'`x'_`q'=(3085+190*10+200*20+215*30 +230*(m3`y'`x' -60))*`p`q''^`e' if m3`y'`x'>60 & codcom==32

foreach t in 1 4{
	replace p1`y'`x'_`t'_`q'=(3085+190*r`y'`x'_`t')*`p`q''^`e' if r`y'`x'_`t'<=10 & codcom==32
	replace p1`y'`x'_`t'_`q'=(3085+190*10+200*(r`y'`x'_`t' -10))*`p`q''^`e' if r`y'`x'_`t'>10 & r`y'`x'_`t'<=30 & codcom==32
	replace p1`y'`x'_`t'_`q'=(3085+190*10+200*20+215*(r`y'`x'_`t' -30))*`p`q''^`e' if r`y'`x'_`t'>30 & r`y'`x'_`t'<=60 & codcom==32
	replace p1`y'`x'_`t'_`q'=(3085+190*10+200*20+215*30 +230*(r`y'`x'_`t' -60))*`p`q''^`e' if r`y'`x'_`t'>60 & codcom==32
	replace s`y'`x'_`t'_`q'=p`y'`x'_`q'-p1`y'`x'_`t'_`q' if  codcom==32
	replace s`y'`x'_`t'_`q'=. if m3`y'`x'==. & codcom==32
	}	
}
}




*2024-2025
**********

local e=3

**** Asada Moracia

foreach y in 2024 2025 {
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
gen p`y'`x'_`q'=(2695+155*m3`y'`x')*`p`q''^`e' if m3`y'`x'<=10 & codcom==64
replace p`y'`x'_`q'=(2695+155*10+170*(m3`y'`x' -10))*`p`q''^`e' if m3`y'`x'>10 & m3`y'`x'<=30 & codcom==64
replace p`y'`x'_`q'=(2695+155*10+170*20+185*(m3`y'`x' -30))*`p`q''^`e' if m3`y'`x'>30 & m3`y'`x'<=60 & codcom==64
replace p`y'`x'_`q'=(2695+155*10+170*20+185*30 +200*(m3`y'`x' -60))*`p`q''^`e' if m3`y'`x'>60 & codcom==64

foreach t in 1 4{
	gen p1`y'`x'_`t'_`q'=(2695+155*r`y'`x'_`t')*`p`q''^`e' if r`y'`x'_`t'<=10 & codcom==64
	replace p1`y'`x'_`t'_`q'=(2695+155*10+170*(r`y'`x'_`t' -10))*`p`q''^`e' if r`y'`x'_`t'>10 & r`y'`x'_`t'<=30 & codcom==64
	replace p1`y'`x'_`t'_`q'=(2695+155*10+170*20+185*(r`y'`x'_`t' -30))*`p`q''^`e' if r`y'`x'_`t'>30 & r`y'`x'_`t'<=60 & codcom==64
	replace p1`y'`x'_`t'_`q'=(2695+155*10+170*20+185*30 +200*(r`y'`x'_`t' -60))*`p`q''^`e' if r`y'`x'_`t'>60 & codcom==64
	gen s`y'`x'_`t'_`q'=p`y'`x'_`q'-p1`y'`x'_`t'_`q' if  codcom==64
	replace s`y'`x'_`t'_`q'=. if m3`y'`x'==. & codcom==64
	}
}
}


/*
Paso Tempisque, Chomes, San Blas, Lepanto 

*/

foreach y in 2024 2025{
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
replace p`y'`x'_`q'=(3415+160*m3`y'`x')*`p`q''^`e' if m3`y'`x' <=10 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
replace p`y'`x'_`q'=(3415+160*10+170*(m3`y'`x' -10))*`p`q''^`e' if m3`y'`x'>10 & m3`y'`x'<=30 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
replace p`y'`x'_`q'=(3415+160*10+170*20+180*(m3`y'`x' -30))*`p`q''^`e' if m3`y'`x'>30 & m3`y'`x'<=60 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
replace p`y'`x'_`q'=(3415+160*10+170*20+180*30 + 195*(m3`y'`x' -60))*`p`q''^`e' if m3`y'`x'>60 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 

foreach t in 1 4{
	replace p1`y'`x'_`t'_`q'=(3415+160*r`y'`x'_`t')*`p`q''^`e' if r`y'`x'_`t'<=10 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
	replace p1`y'`x'_`t'_`q'=(3415+160*10+170*(r`y'`x'_`t' -10))*`p`q''^`e' if r`y'`x'_`t'>10 & r`y'`x'_`t'<=30 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
	replace p1`y'`x'_`t'_`q'=(3415+160*10+170*20+180*(r`y'`x'_`t' -30))*`p`q''^`e' if r`y'`x'_`t'>30 & r`y'`x'_`t'<=60 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
	replace p1`y'`x'_`t'_`q'=(3415+160*10+170*20+180*30 +195*(r`y'`x'_`t' -60))*`p`q''^`e' if r`y'`x'_`t'>60 & (codcom==48 | codcom==36 | codcom==31 | codcom==66) 
	replace s`y'`x'_`t'_`q'=p`y'`x'_`q'-p1`y'`x'_`t'_`q' if  (codcom==48 | codcom==36 | codcom==31 | codcom==66)
	replace s`y'`x'_`t'_`q'=. if m3`y'`x'==. & (codcom==48 | codcom==36 | codcom==31 | codcom==66)
	}

}
}

**** Asada Jocotes

foreach y in 2024 2025{
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
replace p`y'`x'_`q'=(2745+150*m3`y'`x')*`p`q''^`e' if codcom==35

foreach t in 1 4{

	replace p1`y'`x'_`t'_`q'=(2745+150*r`y'`x'_`t')*`p`q''^`e' if codcom==35
	replace s`y'`x'_`t'_`q'=p`y'`x'_`q'-p1`y'`x'_`t'_`q' if  codcom==35
	replace s`y'`x'_`t'_`q'=. if m3`y'`x'==. & codcom==35
	}
}
}

**** Asada Lomas de Matapalo


foreach y in 2024 2025{
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
replace p`y'`x'_`q'=(3180+185*m3`y'`x')*`p`q''^`e' if m3`y'`x' <=10 & codcom==25
replace p`y'`x'_`q'=(3180+185*10+195*(m3`y'`x' -10))*`p`q''^`e' if m3`y'`x'>10 & m3`y'`x'<=30 & codcom==25
replace p`y'`x'_`q'=(3180+185*10+195*20+210*(m3`y'`x' -30))*`p`q''^`e' if m3`y'`x'>30 & m3`y'`x'<=60 & codcom==25 
replace p`y'`x'_`q'=(3180+185*10+195*20+210*30 +225*(m3`y'`x' -60))*`p`q''^`e' if m3`y'`x'>60 & codcom==25 


foreach t in 1 4{

	replace p1`y'`x'_`t'_`q'=(3180+185*r`y'`x'_`t')*`p`q''^`e' if r`y'`x'_`t'<=10 & codcom==25
	replace p1`y'`x'_`t'_`q'=(3180+185*10+195*(r`y'`x'_`t' -10))*`p`q''^`e' if r`y'`x'_`t'>10 & r`y'`x'_`t'<=30 & codcom==25
	replace p1`y'`x'_`t'_`q'=(3180+185*10+195*20+210*(r`y'`x'_`t' -30))*`p`q''^`e' if r`y'`x'_`t'>30 & r`y'`x'_`t'<=60 & codcom==25 
	replace p1`y'`x'_`t'_`q'=(3180+185*10+195*20+210*30 +225*(r`y'`x'_`t' -60))*`p`q''^`e' if r`y'`x'_`t'>60 & codcom==25
	replace s`y'`x'_`t'_`q'=p`y'`x'_`q'-p1`y'`x'_`t'_`q' if codcom==25
	replace s`y'`x'_`t'_`q'=. if m3`y'`x'==. & codcom==25
	}
}

}

**** Asada Pueblo Nuevo

foreach y in 2024 2025{
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
replace p`y'`x'_`q'=(2800+190*m3`y'`x')*`p`q''^`e' if m3`y'`x' <=10 & codcom==47
replace p`y'`x'_`q'=(2800+190*10+200*(m3`y'`x' -10))*`p`q''^`e' if m3`y'`x'>10 & m3`y'`x'<=30 & codcom==47
replace p`y'`x'_`q'=(2800+190*10+200*20+215*(m3`y'`x' -30))*`p`q''^`e' if m3`y'`x'>30 & m3`y'`x'<=60 & codcom==47 
replace p`y'`x'_`q'=(2800+190*10+200*20+215*30 +230*(m3`y'`x' -60))*`p`q''^`e' if m3`y'`x'>60 & codcom==47 

foreach t in 1 4{

	replace p1`y'`x'_`t'_`q'=(2800+190*r`y'`x'_`t')*`p`q''^`e' if r`y'`x'_`t'<=10 & codcom==47
	replace p1`y'`x'_`t'_`q'=(2800+190*10+200*(r`y'`x'_`t' -10))*`p`q''^`e' if r`y'`x'_`t'>10 & r`y'`x'_`t'<=30 & codcom==47
	replace p1`y'`x'_`t'_`q'=(2800+190*10+200*20+215*(r`y'`x'_`t' -30))*`p`q''^`e' if r`y'`x'_`t'>30 & r`y'`x'_`t'<=60 & codcom==47 
	replace p1`y'`x'_`t'_`q'=(2800+190*10+200*20+215*30 +230*(r`y'`x'_`t' -60))*`p`q''^`e' if r`y'`x'_`t'>60 & codcom==47
	replace s`y'`x'_`t'_`q'=p`y'`x'_`q'-p1`y'`x'_`t'_`q' if  codcom==47
	replace s`y'`x'_`t'_`q'=. if m3`y'`x'==. & codcom==47
	}
}
}

**** Asada Santa Rita

foreach y in 2024 2025{
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
replace p`y'`x'_`q'=(3085+190*m3`y'`x')*`p`q''^`e' if m3`y'`x' <=10 & codcom==32
replace p`y'`x'_`q'=(3085+190*10+200*(m3`y'`x' -10))*`p`q''^`e' if m3`y'`x'>10 & m3`y'`x'<=30 & codcom==32
replace p`y'`x'_`q'=(3085+190*10+200*20+215*(m3`y'`x' -30))*`p`q''^`e' if m3`y'`x'>30 & m3`y'`x'<=60 & codcom==32
replace p`y'`x'_`q'=(3085+190*10+200*20+215*30 +230*(m3`y'`x' -60))*`p`q''^`e' if m3`y'`x'>60 & codcom==32

foreach t in 1 4{
	replace p1`y'`x'_`t'_`q'=(3085+190*r`y'`x'_`t')*`p`q''^`e' if r`y'`x'_`t'<=10 & codcom==32
	replace p1`y'`x'_`t'_`q'=(3085+190*10+200*(r`y'`x'_`t' -10))*`p`q''^`e' if r`y'`x'_`t'>10 & r`y'`x'_`t'<=30 & codcom==32
	replace p1`y'`x'_`t'_`q'=(3085+190*10+200*20+215*(r`y'`x'_`t' -30))*`p`q''^`e' if r`y'`x'_`t'>30 & r`y'`x'_`t'<=60 & codcom==32
	replace p1`y'`x'_`t'_`q'=(3085+190*10+200*20+215*30 +230*(r`y'`x'_`t' -60))*`p`q''^`e' if r`y'`x'_`t'>60 & codcom==32
	replace s`y'`x'_`t'_`q'=p`y'`x'_`q'-p1`y'`x'_`t'_`q' if  codcom==32
	replace s`y'`x'_`t'_`q'=. if m3`y'`x'==. & codcom==32
	}	
}
}


}


*Constructing different lifespans: either 2 years (worst) or 9 years (best)


foreach y in 2015 2016 {
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
gen s`y'`x'_1_1_1=s`y'`x'_1_1
gen s`y'`x'_1_4_1=s`y'`x'_1_4
gen s`y'`x'_4_1_1=s`y'`x'_4_1
gen s`y'`x'_4_4_1=s`y'`x'_4_4
gen s`y'`x'_1_1_4=s`y'`x'_1_1
gen s`y'`x'_1_4_4=s`y'`x'_1_4
gen s`y'`x'_4_1_4=s`y'`x'_4_1
gen s`y'`x'_4_4_4=s`y'`x'_4_4
}
}
foreach y in 2017{
foreach x in 01 02 03 04 05{
gen s`y'`x'_1_1_1=s`y'`x'_1_1
gen s`y'`x'_1_4_1=s`y'`x'_1_4
gen s`y'`x'_4_1_1=s`y'`x'_4_1
gen s`y'`x'_4_4_1=s`y'`x'_4_4
gen s`y'`x'_1_1_4=s`y'`x'_1_1
gen s`y'`x'_1_4_4=s`y'`x'_1_4
gen s`y'`x'_4_1_4=s`y'`x'_4_1
gen s`y'`x'_4_4_4=s`y'`x'_4_4
}
}

foreach y in 2017{
foreach x in 06 07 08 09 10 11 12{
gen s`y'`x'_1_1_1=s`y'`x'_1_1
gen s`y'`x'_1_4_1=s`y'`x'_1_4
gen s`y'`x'_4_1_1=s`y'`x'_4_1
gen s`y'`x'_4_4_1=s`y'`x'_4_4
gen s`y'`x'_1_1_4=0
gen s`y'`x'_1_4_4=0
gen s`y'`x'_4_1_4=0
gen s`y'`x'_4_4_4=0
}
}

foreach y in 2018 2019 2020 2021 2022 2023 2024{
foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
gen s`y'`x'_1_1_1=s`y'`x'_1_1
gen s`y'`x'_1_4_1=s`y'`x'_1_4
gen s`y'`x'_4_1_1=s`y'`x'_4_1
gen s`y'`x'_4_4_1=s`y'`x'_4_4
gen s`y'`x'_1_1_4=0
gen s`y'`x'_1_4_4=0
gen s`y'`x'_4_1_4=0
gen s`y'`x'_4_4_4=0
}
}

*p1* is with technology

set more off


*Exchange rate 527 Colones is a Dollar
	*Investment in May 2015
	*I assume that everybody received treatment since June, not just the 4 communities. There is no reason to make to introduce the real timing.


*Difference of utility.
***********************

*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 	*Manual change for (ii): Activate probability weights under EUT or RDU 
/*	
	local w1=0.125
	local w2=0.125
	local w3=0.125
	local w4=0.125
	local w5=0.125
	local w6=0.125
	local w7=0.125
	local w8=0.125	
	
*/
		
	local w1=0.4993
	local w2=0.0960
	local w3=0.0721
	local w4=0.0624
	local w5=0.0583
	local w6=0.0579
	local w7=0.0622
	local w8=0.0917 

*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	  
	  
	  
*#####################
*Individuals
*#####################

	*Individuals: discount rate 30%, r=0.81
	***************************

/* Method to get the CE (CE per period and then discount it). We collect savings since June 2015. */
	************************************************************

	
	*CRRA parameter for individuals
	*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	*Manual change for (ii): Activate row for risk neutral (0) or risk averse (81 for individuals)
	
	local r1=81
	*local r1=0
	*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	
	
	local r=`r1'/100

	local j=2024
	
	foreach g in 2 4 7 8 9 10 11 12 13 14 15 16 17 18 19 20 30 44{
	gen gain_`r1'_`g'_`j'=0
	
	local i=1
	foreach x in 06 07 08 09 10 11 12{

	foreach a in 1 4{
			foreach b in 1 4{
				foreach c in 1 4{
			sum s2015`x'_`a'_`b'_`c'
			local diff_2015`x'_`a'_`b'_`c'=r(mean)*(1/527)

				}
			}
		}
	replace gain_`r1'_`g'_`j'=gain_`r1'_`g'_`j' + ((1/(1+`g'/100))^(`i'/12))*(((1-`r')*(`w1'*(`diff_2015`x'_1_1_1'^(1-`r'))/(1-`r') + `w2'*(`diff_2015`x'_1_4_1'^(1-`r'))/(1-`r') + `w3'*(`diff_2015`x'_4_1_1'^(1-`r'))/(1-`r') + `w4'*(`diff_2015`x'_4_4_1'^(1-`r'))/(1-`r')+`w5'*(`diff_2015`x'_1_1_4'^(1-`r'))/(1-`r') + `w6'*(`diff_2015`x'_1_4_4'^(1-`r'))/(1-`r') + `w7'*(`diff_2015`x'_4_1_4'^(1-`r'))/(1-`r') + `w8'*(`diff_2015`x'_4_4_4'^(1-`r'))/(1-`r')))^(1/(1-`r')))

	
	local i=`i'+1
	}
	
	

	

	local i=8
	foreach y in 2016 2017 2018 2019 2020 2021 2022 2023 2024{
	foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
	
	foreach a in 1 4{
			foreach b in 1 4{
				foreach c in 1 4{
			sum s`y'`x'_`a'_`b'_`c'
			local diff_`y'`x'_`a'_`b'_`c'=r(mean)*(1/527)

				}
			}
		}
	replace gain_`r1'_`g'_`j'=gain_`r1'_`g'_`j' + ((1/(1+`g'/100))^(`i'/12))*(((1-`r')*(`w1'*(`diff_`y'`x'_1_1_1'^(1-`r'))/(1-`r') + `w2'*(`diff_`y'`x'_1_4_1'^(1-`r'))/(1-`r') + `w3'*(`diff_`y'`x'_4_1_1'^(1-`r'))/(1-`r') + `w4'*(`diff_`y'`x'_4_4_1'^(1-`r'))/(1-`r')+`w5'*(`diff_`y'`x'_1_1_4'^(1-`r'))/(1-`r') + `w6'*(`diff_`y'`x'_1_4_4'^(1-`r'))/(1-`r') + `w7'*(`diff_`y'`x'_4_1_4'^(1-`r'))/(1-`r') + `w8'*(`diff_`y'`x'_4_4_4'^(1-`r'))/(1-`r')))^(1/(1-`r'))) if  `y'`x'<`j'06

	local i=`i'+1
	}
	}

	}
	
	
	
	
	

	
*#####################
*Couples
*#####################
	* Couples: discount rate 44%, r=0.77
	************************************
	

 /* Method to get the CE (CE per period and then discount it) */
	************************************************************
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~	
*Manual change for (ii): Activate or deactivate probability weights 
/*	 
*/	
local w1=0.5244
	local w2=0.0809
	local w3=0.0616
	local w4=0.0544
	local w5=0.0522
	local w6=0.0539
	local w7=0.0615
	local w8=0.1110 
  
 
 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
  
  	*CRRA parameter for couples
	*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	*Manual change for (ii): Activate row for risk neutral (0) or risk averse (77 for couples)
	local r1=77
	*local r1=0
	*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	local r=`r1'/100

	local j=2024
	foreach g in 2 4 7 8 9 10 11 12 13 14 15 16 17 18 19 20 30 44{
	gen gain_`r1'_`g'_`j'=0
	
	local i=1
	foreach x in 06 07 08 09 10 11 12{

	foreach a in 1 4{
			foreach b in 1 4{
				foreach c in 1 4{
			sum s2015`x'_`a'_`b'_`c'
			local diff_2015`x'_`a'_`b'_`c'=r(mean)*(1/527)

				}
			}
		}
	replace gain_`r1'_`g'_`j'=gain_`r1'_`g'_`j' + ((1/(1+`g'/100))^(`i'/12))*(((1-`r')*(`w1'*(`diff_2015`x'_1_1_1'^(1-`r'))/(1-`r') + `w2'*(`diff_2015`x'_1_4_1'^(1-`r'))/(1-`r') + `w3'*(`diff_2015`x'_4_1_1'^(1-`r'))/(1-`r') + `w4'*(`diff_2015`x'_4_4_1'^(1-`r'))/(1-`r')+`w5'*(`diff_2015`x'_1_1_4'^(1-`r'))/(1-`r') + `w6'*(`diff_2015`x'_1_4_4'^(1-`r'))/(1-`r') + `w7'*(`diff_2015`x'_4_1_4'^(1-`r'))/(1-`r') + `w8'*(`diff_2015`x'_4_4_4'^(1-`r'))/(1-`r')))^(1/(1-`r')))

	
	local i=`i'+1
	}
	
	

	

	local i=8
	foreach y in 2016 2017 2018 2019 2020 2021 2022 2023 2024{
	foreach x in 01 02 03 04 05 06 07 08 09 10 11 12{
	
	foreach a in 1 4{
			foreach b in 1 4{
				foreach c in 1 4{
			sum s`y'`x'_`a'_`b'_`c'
			local diff_`y'`x'_`a'_`b'_`c'=r(mean)*(1/527)

				}
			}
		}
	replace gain_`r1'_`g'_`j'=gain_`r1'_`g'_`j' + ((1/(1+`g'/100))^(`i'/12))*(((1-`r')*(`w1'*(`diff_`y'`x'_1_1_1'^(1-`r'))/(1-`r') + `w2'*(`diff_`y'`x'_1_4_1'^(1-`r'))/(1-`r') + `w3'*(`diff_`y'`x'_4_1_1'^(1-`r'))/(1-`r') + `w4'*(`diff_`y'`x'_4_4_1'^(1-`r'))/(1-`r')+`w5'*(`diff_`y'`x'_1_1_4'^(1-`r'))/(1-`r') + `w6'*(`diff_`y'`x'_1_4_4'^(1-`r'))/(1-`r') + `w7'*(`diff_`y'`x'_4_1_4'^(1-`r'))/(1-`r') + `w8'*(`diff_`y'`x'_4_4_4'^(1-`r'))/(1-`r')))^(1/(1-`r'))) if  `y'`x'<`j'06

	local i=`i'+1
	}
	}

	}
	
	

*/
	sum gain_* 
	
*###########################	
*Preparing table
*###########################	

matrix utd=J(36,1,.)
local i=1
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*Manual change for (ii): Activate row for risk neutral (0) or risk averse (81,77)
*foreach r1 in 0{
foreach r1 in 81 77{
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~	
foreach g in 2 4 7 8 9 10 11 12 13 14 15 16 17 18 19 20 30 44{
	foreach z in 2024{
	sum gain_`r1'_`g'_`z'
	local m=r(mean)
	matrix utd[`i',1]=`m'	

	}
	local i=`i'+1

}
}



matrix colnames utd = year`j'
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*Manual change for (ii): Activate matrix rownames for risk neutral (0) or risk averse (81,77)
matrix rownames utd= 81_2%_gain 81_4%_gain 81_7%_gain 81_8%_gain 81_9%_gain 81_10%_gain 81_11%_gain 81_12%_gain 81_13%_gain 81_14%_gain 81_15%_gain 81_16%_gain 81_17%_gain 81_18%_gain 81_19%_gain 81_20%_gain 81_30%_gain 81_44%_gain 77_2%_gain 77_4%_gain 77_7%_gain 77_8%_gain 77_9%_gain 77_10%_gain 77_11%_gain 77_12%_gain 77_13%_gain 77_14%_gain 77_15%_gain 77_16%_gain 77_17%_gain 77_18%_gain 77_19%_gain 77_20%_gain 77_30%_gain 77_44%_gain
*matrix rownames utd=0_2%_gain 0_4%_gain 0_7%_gain 0_8%_gain 0_9%_gain 0_10%_gain 0_11%_gain 0_12%_gain 0_13%_gain 0_14%_gain 0_15%_gain 0_16%_gain 0_17%_gain 0_18%_gain 0_19%_gain 0_20%_gain 0_30%_gain 0_44%_gain
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

matrix list utd
 

